package model

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ SmsSeckillSkuRelationModel = (*customSmsSeckillSkuRelationModel)(nil)

type (
	// SmsSeckillSkuRelationModel is an interface to be customized, add more methods here,
	// and implement the added methods in customSmsSeckillSkuRelationModel.
	SmsSeckillSkuRelationModel interface {
		smsSeckillSkuRelationModel
		FindBySessionId(ctx context.Context, sessionId int64) ([]SmsSeckillSkuRelation, error)
	}

	customSmsSeckillSkuRelationModel struct {
		*defaultSmsSeckillSkuRelationModel
	}
)

func (c *customSmsSeckillSkuRelationModel) FindBySessionId(ctx context.Context, sessionId int64) ([]SmsSeckillSkuRelation, error) {
	var list []SmsSeckillSkuRelation
	query := fmt.Sprintf("SELECT * FROM sms_seckill_sku_relation  WHERE promotion_session_id = ?")
	err := c.conn.QueryRowsCtx(ctx, &list, query, sessionId)
	if err != nil {
		logx.Error(err)
		return nil, err
	}
	return list, err
}

// NewSmsSeckillSkuRelationModel returns a model for the database table.
func NewSmsSeckillSkuRelationModel(conn sqlx.SqlConn) SmsSeckillSkuRelationModel {
	return &customSmsSeckillSkuRelationModel{
		defaultSmsSeckillSkuRelationModel: newSmsSeckillSkuRelationModel(conn),
	}
}
